﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MementoClient.Interfaces;
using MementoClientConnectorInterfaces;

namespace MementoClient.Classes
{
    public class UserTasksRetriever : IUserTasksRetriever
    {
        private readonly IClientConnectorRetriever clientConnectorRetriever;

        public UserTasksRetriever(IClientConnectorRetriever clientConnectorRetriever)
        {
            this.clientConnectorRetriever = clientConnectorRetriever;
        }

        public IEnumerable<Task> GetTasksForUser(string userName)
        {
            var clientConnectors = clientConnectorRetriever.Retrieve();
            var tasks = new List<Task>();
            foreach(var clientConnector in clientConnectors)
            {
                var configurations = clientConnector.GetConfigurations();
                foreach(var configuration in configurations)
                {
                    foreach (var task in clientConnector.GetTasksForUser(configuration.UniqueID, userName))
                    {
                        task.ProjectID = configuration.UniqueID + "_" + task.ProjectID;
                        task.TaskID = configuration.UniqueID + "_" + task.TaskID;
                        tasks.Add(task);
                    }
                }
            }
            return tasks;
        }
    }
}
